
function class(name, inherit, parent)
	inherit.__className = name
	inherit.__parent = parent
	setmetatable(inherit, {
		__index = function (tb, key)
			local rt = nil
			local __overrideIndex = rawget(tb, '__overrideIndex')

			if __overrideIndex then rt = __overrideIndex(tb, key) end

			if not rt then
				if __parent and __parent[key] then rt = __parent[key] end
			end
			return rt
		end,

		__newindex = function (tb, key, value)
			local rt = nil
			local __overrideNewIndex = rawget(tb, '__overrideNewIndex')

			if __overrideNewIndex then __overrideNewIndex(tb, key, value) end

			if not rt then
				if __parent and __parent.__overrideNewIndex then 
					rt = __parent.__overrideNewIndex(tb, key, value)
				else
					rawset(tb, key, value)
				end
			end
		end,

		new = function (...)
			local obj = {}
			setmetatable(obj, inherit)
			if obj.__constructor then
				obj.__constructor(...)
			end
		end,
	})

end


